﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using log4net;

namespace MND.Worlds
{
    class World : Commands.CommandProcessor
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(World));

        private string name;
        private bool isEnabled;

        public string Name { get { return name; } set { name = value; } }
        public bool IsEnabled { get { return isEnabled; } set { isEnabled = value; } }

        private IngameCommandProcessor processor;

        public static World Load(string name)
        {
            try
            {
                DBWorldsDataContext WorldsDB = new DBWorldsDataContext();

                var worldData = (from world in WorldsDB.dbWorlds
                             where world.Name == name
                             select world).First();

                World w = new World() { Name = worldData.Name, IsEnabled = worldData.Enabled };
                return w;
            }
            catch (Exception e)
            {
                log.Error("Error occured while loading world: " + name, e);
                throw new WorldException(name, "Exception while loading", e);
            }
        }

        public void EnqueueCommand(Commands.UserCommand uc)
        {
            processor.Enqueue(uc);
        }
    }
}
